package cn.itsource.controller;

import cn.itsource.domain.Order;
import cn.itsource.service.IOrderService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @GetMapping("/order/getById/{id}")
    @SentinelResource(value = "getById", blockHandler = "orderError")
    public Order getById(@PathVariable("id") Integer id) {
        return orderService.getById(id);
    }

    public Order orderError(@PathVariable("id") Integer id,BlockException e){
        e.printStackTrace();
        System.out.println("限流了");
        return new Order();
    }
}
